package fifteenth.Java反射机制的深入应用;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class 调用类中的方法 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class<?> c = Class.forName("fifteenth.取得类的结构.Person");
        Method method = c.getMethod("sayChina");//此方法没有参数
        method.invoke(c.newInstance());//调用方法 必须传递对象实例

       /* Class<?> c = null;
        try {
            c = Class.forName("fifteenth.取得类的结构.Person");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        Method method = null;
        try {
            method = c.getMethod("sayChina");
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        try {
            method.invoke(c.newInstance());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }*/
    }
}
/**
 * 因为sayChina()方法上没有任何的参数，素以此处没有设置参数类型和参数内容
 */
/*
C:\Java\jdk1.8.0_201\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=51839:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -classpath C:\Java\jdk1.8.0_201\jre\lib\charsets.jar;C:\Java\jdk1.8.0_201\jre\lib\deploy.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\access-bridge-64.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\cldrdata.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\dnsns.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\jaccess.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\jfxrt.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\localedata.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\nashorn.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\sunec.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\sunjce_provider.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\sunmscapi.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\sunpkcs11.jar;C:\Java\jdk1.8.0_201\jre\lib\ext\zipfs.jar;C:\Java\jdk1.8.0_201\jre\lib\javaws.jar;C:\Java\jdk1.8.0_201\jre\lib\jce.jar;C:\Java\jdk1.8.0_201\jre\lib\jfr.jar;C:\Java\jdk1.8.0_201\jre\lib\jfxswt.jar;C:\Java\jdk1.8.0_201\jre\lib\jsse.jar;C:\Java\jdk1.8.0_201\jre\lib\management-agent.jar;C:\Java\jdk1.8.0_201\jre\lib\plugin.jar;C:\Java\jdk1.8.0_201\jre\lib\resources.jar;C:\Java\jdk1.8.0_201\jre\lib\rt.jar;D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 fifteenth.Java反射机制的深入应用.调用类中的方法
作者：业成,国籍：China

Process finished with exit code 0
 */